Skip to content

docs: Add docs for horizontal orientation#9843

Merged
LFDanLu merged 11 commits intomainfrom
docs_for_release
Mar 28, 2026
Merged

docs: Add docs for horizontal orientation#9843
LFDanLu merged 11 commits intomainfrom
docs_for_release

Conversation

@LFDanLu
Copy link
Copy Markdown
Member

@LFDanLu LFDanLu commented Mar 25, 2026

Part of audit

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Check out the docs updates

🧢 Your Project:

RSP

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 25, 2026

constructor(options: ListLayoutOptions = {}) {
super();
this.rowHeight = options.rowHeight ?? null;
this.rowHeight = options?.rowSize ?? options?.rowHeight ?? null;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also go ahead and change these height properties to be size as well, would just need to make it back compat with additional getters. Not sure if worth it if those would stick around for quite some time, but might reduce confusion

this.headingHeight = options.headingHeight ?? null;
this.estimatedHeadingHeight = options.estimatedHeadingHeight ?? null;
this.loaderHeight = options.loaderHeight ?? null;
this.estimatedRowHeight = options?.estimatedRowSize ?? options?.estimatedRowHeight ?? null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we want to change all the internal variables to size as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o, i think that's what you were saying here #9843 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, thats right. I might try and do it to see how bad it is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, when working on this I was kind of unsure whether to use "size" here, since that typically refers to a 2-dimensional value in the context of our virtualizer package. I think it's fine, but wanted to share it for consideration - naming is hard 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yeah, I had a similar thought but couldn't think up of a better alternative either. I'll see about pushing up the full changes and then see if we can land on a better name

grid-template-columns: auto;
align-items: center;

&[data-orientation=horizontal] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need this in the tailwind starter as well

selectionMode="multiple"
items={items}
style={{display: 'block', padding: 0, height: 100}}>
{(item) => <ListBoxItem style={{height: '100%'}}>{item.name}</ListBoxItem>}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add some styles to the items so that it's clear where one ends and the next begins. Right now it just looks like a long string of text with some random break in it.

It'd also be nice if this was an example I'd want to use, so if we can make them basically more like cards with a title and description, that'd be better

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 26, 2026


Use the `orientation` option to arrange items horizontally or vertically. Provide the same `orientation` on the collection component so keyboard navigation matches the layout.

```tsx render docs={docs.exports.ListLayoutOptions} links={docs.links} props={['gap', 'padding']} initialProps={{estimatedRowSize: 300, gap: 8, padding: 8, orientation: 'horizontal'}} propsObject="layoutOptions" wide
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance we make the images a tad bit smaller

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 26, 2026

snowystinger
snowystinger previously approved these changes Mar 27, 2026
Copy link
Copy Markdown
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smaller images in the cards would be nice, otherwise looks good

Co-authored-by: Yihui Liao <44729383+yihuiliao@users.noreply.github.com>
@nwidynski
Copy link
Copy Markdown
Contributor

nwidynski commented Mar 27, 2026

@LFDanLu Has the issue found in testing already been taken care of? Otherwise I will open up a PR with a fix for that.

Comment on lines +316 to +329
<ListBox
/*- begin highlight -*/
orientation="horizontal"
/*- end highlight -*/
aria-label="Horizontal virtualized list"
selectionMode="multiple"
items={imageOptions}
style={{display: 'block', padding: 0, height: 250}}>
{(item) => (
<ListBoxItem textValue={item.title} aria-label={item.title} style={{height: '100%', padding: 12, overflow: 'hidden', boxSizing: 'border-box', border: '2px solid var(--border-color)', borderRadius: 8}}>
<img src={item.image} alt="" style={{maxHeight: 200, aspectRatio: item.aspectRatio, borderRadius: 4}} />
</ListBoxItem>
)}
</ListBox>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yihuiliao @snowystinger I opted to just go for a simpler change and get rid of the text, was getting a lot of grief with the virtualized card sizing vs getting the img width to be variable and clamped + making the text overflow work without making this example overly complicated

@LFDanLu
Copy link
Copy Markdown
Member Author

LFDanLu commented Mar 27, 2026

@nwidynski mind jogging my memory about what exact issue that was haha.

@nwidynski
Copy link
Copy Markdown
Contributor

nwidynski commented Mar 27, 2026

I think it was just that the styles I added in storybook spread to the combobox stories (see spreadsheet comment). would also take care of the nits that devon mentioned when approving.

Edit: Seems to have been already done in #9845

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 27, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 27, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 27, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 27, 2026

## API Changes

react-aria-components

/react-aria-components:TableLayout

 TableLayout <O extends TableLayoutProps = TableLayoutProps, T> {
-  constructor: (ListLayoutOptions) => void
+  constructor: (TableLayoutProps) => void
   getContentSize: () => Size
   getDropTargetFromPoint: (number, number, (DropTarget) => boolean) => DropTarget | null
   getDropTargetLayoutInfo: (ItemDropTarget) => LayoutInfo
   getLayoutInfo: (Key) => LayoutInfo | null
   shouldInvalidate: (Rect, Rect) => boolean
   shouldInvalidateLayoutOptions: (TableLayoutProps, TableLayoutProps) => boolean
   update: (InvalidationContext<TableLayoutProps>) => void
   updateItemSize: (Key, Size) => boolean
   useLayoutOptions: () => TableLayoutProps
   virtualizer: Virtualizer<{}, any> | null
 }

/react-aria-components:ListLayoutOptions

 ListLayoutOptions {
   dropIndicatorThickness?: number = 2
-  estimatedHeadingHeight?: number
-  estimatedRowHeight?: number
+  estimatedHeadingSize?: number
+  estimatedRowSize?: number
   gap?: number = 0
-  headingHeight?: number = 48
-  loaderHeight?: number = 48
+  headingSize?: number = 48
+  loaderSize?: number = 48
   orientation?: Orientation = 'vertical'
   padding?: number = 0
-  rowHeight?: number = 48
+  rowSize?: number = 48
 }

/react-aria-components:TableLayoutProps

+TableLayoutProps {
+  columnWidths?: Map<Key, number>
+  dropIndicatorThickness?: number = 2
+  estimatedHeadingHeight?: number
+  estimatedRowHeight?: number
+  gap?: number = 0
+  headingHeight?: number = 48
+  loaderHeight?: number = 48
+  padding?: number = 0
+  rowHeight?: number = 48
+}

@react-spectrum/s2

/@react-spectrum/s2:ListView

 ListView <T extends {}> {
   UNSAFE_className?: UnsafeClassName
   UNSAFE_style?: CSSProperties
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children: ReactNode | ({}) => ReactNode
   defaultSelectedKeys?: 'all' | Iterable<Key>
   dependencies?: ReadonlyArray<any>
   disabledBehavior?: DisabledBehavior = "all"
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   disallowTypeAhead?: boolean = false
   escapeKeyBehavior?: 'clearSelection' | 'none' = 'clearSelection'
   hideLinkOutIcon?: boolean
   id?: string
   isQuiet?: boolean
   items?: Iterable<T>
   loadingState?: LoadingState
   onAction?: (Key) => void
   onLoadMore?: () => void
   onSelectionChange?: (Selection) => void
-  orientation?: Orientation = 'vertical'
   overflowMode?: 'wrap' | 'truncate' = 'truncate'
   renderActionBar?: ('all' | Set<Key>) => ReactElement
   renderEmptyState?: (GridListRenderProps) => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionStyle?: 'highlight' | 'checkbox' = 'checkbox'
   shouldSelectOnPressUp?: boolean
   slot?: string | null
   styles?: StylesPropWithHeight
 }

/@react-spectrum/s2:ListViewProps

 ListViewProps <T> {
   UNSAFE_className?: UnsafeClassName
   UNSAFE_style?: CSSProperties
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean | FocusStrategy
   children: ReactNode | (T) => ReactNode
   defaultSelectedKeys?: 'all' | Iterable<Key>
   dependencies?: ReadonlyArray<any>
   disabledBehavior?: DisabledBehavior = "all"
   disabledKeys?: Iterable<Key>
   disallowEmptySelection?: boolean
   disallowTypeAhead?: boolean = false
   escapeKeyBehavior?: 'clearSelection' | 'none' = 'clearSelection'
   hideLinkOutIcon?: boolean
   id?: string
   isQuiet?: boolean
   items?: Iterable<T>
   loadingState?: LoadingState
   onAction?: (Key) => void
   onLoadMore?: () => void
   onSelectionChange?: (Selection) => void
-  orientation?: Orientation = 'vertical'
   overflowMode?: 'wrap' | 'truncate' = 'truncate'
   renderActionBar?: ('all' | Set<Key>) => ReactElement
   renderEmptyState?: (GridListRenderProps) => ReactNode
   selectedKeys?: 'all' | Iterable<Key>
   selectionStyle?: 'highlight' | 'checkbox' = 'checkbox'
   shouldSelectOnPressUp?: boolean
   slot?: string | null
   styles?: StylesPropWithHeight
 }

@react-stately/layout

/@react-stately/layout:TableLayout

 TableLayout <O extends TableLayoutProps = TableLayoutProps, T> {
-  constructor: (ListLayoutOptions) => void
+  constructor: (TableLayoutProps) => void
   getContentSize: () => Size
   getDropTargetFromPoint: (number, number, (DropTarget) => boolean) => DropTarget | null
   getDropTargetLayoutInfo: (ItemDropTarget) => LayoutInfo
   getLayoutInfo: (Key) => LayoutInfo | null
   shouldInvalidate: (Rect, Rect) => boolean
   shouldInvalidateLayoutOptions: (TableLayoutProps, TableLayoutProps) => boolean
   update: (InvalidationContext<TableLayoutProps>) => void
   updateItemSize: (Key, Size) => boolean
   virtualizer: Virtualizer<{}, any> | null
 }

/@react-stately/layout:ListLayoutOptions

 ListLayoutOptions {
   dropIndicatorThickness?: number = 2
-  estimatedHeadingHeight?: number
-  estimatedRowHeight?: number
+  estimatedHeadingSize?: number
+  estimatedRowSize?: number
   gap?: number = 0
-  headingHeight?: number = 48
-  loaderHeight?: number = 48
+  headingSize?: number = 48
+  loaderSize?: number = 48
   orientation?: Orientation = 'vertical'
   padding?: number = 0
-  rowHeight?: number = 48
+  rowSize?: number = 48
 }

/@react-stately/layout:TableLayoutProps

 TableLayoutProps {
   columnWidths?: Map<Key, number>
   dropIndicatorThickness?: number = 2
   estimatedHeadingHeight?: number
   estimatedRowHeight?: number
   gap?: number = 0
   headingHeight?: number = 48
   loaderHeight?: number = 48
-  orientation?: Orientation = 'vertical'
   padding?: number = 0
   rowHeight?: number = 48
 }

@LFDanLu LFDanLu added this pull request to the merge queue Mar 28, 2026
Merged via the queue into main with commit 2fd3c81 Mar 28, 2026
29 checks passed
@LFDanLu LFDanLu deleted the docs_for_release branch March 28, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants